package com.example.service;

import com.example.entity.MaterialEntity;
import com.example.entity.MaterialSearchEntity;
import com.example.mapper.MaterialMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class MaterialService {
    @Autowired
    MaterialMapper materialMapper;
    public List<MaterialEntity> findAll() {
        return materialMapper.findAll();
    }
    public List<MaterialEntity> materialSearch(MaterialSearchEntity materialSearch) {
        return materialMapper.materialSearch(materialSearch);
    }
    public int materialSearchCount(MaterialSearchEntity materialSearch) {
        return materialMapper.materialSearchCount(materialSearch);
    }
    public boolean saveMaterial(String method, MaterialEntity materialEntity){
        if (method.equals("修改")) { //有id 为修改操作
            return materialMapper.update(materialEntity);
        } else { //添加操作
            return materialMapper.insert(materialEntity);
        }
    }

    /**
     * 删除设备信息
     *
     * @param id 设备ID
     * @return 如果删除成功，则返回true；否则返回false
     */
    public boolean deleteMaterial(int id){
        return materialMapper.delete(id);
    }



}
